<template>
	<view>
		<!--pages/Seckill-purchase/Seckill-purchase.wxml-->
		<view v-if="!empty">
			<image v-if="show_image" class="banner" :src="show_image" mode="widthFix"></image>
			<view class="title" v-if="spike_list.length">秒杀商品</view>
			<view class="listsbox" v-for="(item, index) in spike_list" :key="index">
				<view class="lists">
					<view class="lists-left">
						<image mode="aspectFit" :src="item.image"></image>
					</view>
					<view class="lists-right">
						<view class="lists-right-a">{{item.name}} {{item.sku || ''}}</view>
						<view class="lists-right-b">已售 {{item.sell_number}}件</view>
						<view class="lists-right-c">
							<view class="lists-right-c-l">
								<view class="lists-right-c-l-a">￥{{item.spike_price}}</view>
								<view class="lists-right-c-l-c">原价：<text>￥{{ item.online_price }}</text></view>
							</view>
							<view @tap="todetail" class="lists-right-c-r" :data-id="item.id">抢购</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>暂无秒杀活动</view>
	</view>
</template>

<script>
	// pages/Seckill-purchase/Seckill-purchase.js
	var app = getApp().globalData;

	export default {
		data() {
			return {
				show_image: '',
				spike_list: [],
				empty: false
			};
		},

		components: {},
		props: {},
		onLoad(options) {
			// #ifdef MP-ALIPAY
			if (JSON.stringify(options) == '{}') {
				options = my.getLaunchOptionsSync().query;
			}
			// #endif
			if (options && (options.store_id)) {
				this.$store.store_id = options.store_id;
			}
		},
		// 加载页面
		onShow() {
			this.getAllSpikeList();
		},
		onShareAppMessage() {
			return {
				title: '秒杀',
				path: '/pages/index/Seckill-purchase/Seckill-purchase?store_id=' + this.$store.store_id + '&share_uid=' + app.XcxData.userInfo.uid,
			};
		},
		methods: {
			//首页详情
			getAllSpikeList: function() {
				var that = this;
				getApp().globalData.sendRequest({
					url: '/spike/getAllSpikeList',
					type: 'post',

					success(res) {
						console.log(res);

						if (res.status == 1) {
							that.setData({
								show_image: res.show_image,
								spike_list: res.all_spike_list
							});
						} else {
							that.setData({
								empty: true
							});
						}
					}

				});
			},
			todetail: function(e) {
				var id = e.currentTarget.dataset.id;
				uni.navigateTo({
					url: '../Seckill-purchase-details/Seckill-purchase-details?id=' + id
				});
			}
		}
	};
</script>
<style>
	@import "./Seckill-purchase.css";
</style>
